<?php
namespace app\common\service\api\service;
use app\common\service\api\interfaces\DictionaryValueApi;
use app\common\exception\TokenException;
use app\common\exception\LogicException;
use think\db\exception\DataNotFoundException;
class DictionaryValueApiService implements DictionaryValueApi{
    //获取字典值列表带分页
    public function getDictionaryValueListPage(){
        $requestData = input();
        $where[] = ['dictionary_id', '=',   $requestData['dictionary_id']];
        $list=app('dictionary_value_ability')->getListPage($where);
        if ($list->isEmpty()) {
            throw new DataNotFoundException(lang('DATA_NOT_FOUND'));
        } else {
            $data['total'] = app('dictionary_value_ability')->getCount($where);
            $data['list'] = $list;
            return $data;
        }
        return $requestData;
    }
    //添加字典值
    public function saveDictionaryValueAdd(){
        $requestData = input();
        $requestData['status'] = 1;
        $result= app('dictionary_value_ability')->saveAdd($requestData);
        if ($result !== false) {
            return $result;
        } else {
            throw new LogicException(lang('SAVE_ERROR'), 10006);
        }
    }
    //获取字典值
    public function getDictionaryValueRow(){
        $requestData = input();
        $where[] = ['value_id', '=', $requestData['value_id']];
        $valueRow= app('dictionary_value_ability')->getLine($where);
        if (empty($valueRow)) {
            throw new DataNotFoundException(lang('DATA_NOT_FOUND'));
        } else {
            return $valueRow;
        }
    }
    //编辑字典值
    public function saveDictionaryValueEdit(){
        $this->getDictionaryValueRow();
        $requestData = input();
        $result =app('dictionary_value_ability')->saveEdit($requestData);;
        if ($result !== false) {
            return $result;
        } else {
            throw new LogicException(lang('SAVE_ERROR'));
        }
    }
    //删除字典值
    public function saveDictionaryValueDel(){
        $valueRow=$this->getDictionaryValueRow();
        $requestData = input();
        $result =app('dictionary_value_ability')->saveDel($requestData);;
        if ($result !== false) {
            return $result;
        } else {
            throw new LogicException(lang('DEL_ERROR'));
        }
    }
    
}